<?php
declare (strict_types=1);

namespace app\admin\service\finance;

use app\common\service\BaseService;
use app\school\logic\school\admin\SchoolBalanceFlow;
use eduline\admin\libs\pageform\FormItem;
use eduline\admin\libs\pagelist\ListItem;
use eduline\admin\page\PageForm;
use eduline\admin\page\PageList;
use think\facade\Request;

/**
 * 充值配置
 */
class SchoolFlow extends BaseService
{
    /**
     * 充值记录
     *
     * @return mixed
     */
    public function recharge()
    {
        $mhm_id = request()->mhm_id;
        $map    = [
            'flow_type' => 1,
            'school_id' => $mhm_id
        ];
        if (Request::has('time', 'get', true)) {
            $map['time_slot'] = Request::get('time/a');
        }

        $data = app(SchoolBalanceFlow::class)->getRecordList($map);

        // 定义字段
        $keyList = [
            'create_time'     => ListItem::make()->title('时间'),
            'price'           => ListItem::make('custom')->title('充值金额'),
            'real_price'      => ListItem::make('custom')->title('实付金额'),
            'balance'         => ListItem::make('custom')->title('变动后金额'),
            'admin_user_name' => ListItem::make()->title('操作人'),
            'notes'           => ListItem::make()->title('备注'),
        ];

        // 搜索字段
        $searchKey = [
            'time' => FormItem::make('date')->title(false)->dateType(FormItem::option('DateType', 'DATE_RANGE'))->startPlaceholder('开始时间')->endPlaceholder('结束时间')->format('yyyy-MM-dd')
        ];

        // 设置表单
        $list = app(PageList::class);
        // 表单字段
        $list->pageKey   = $keyList;
        $list->searchKey = $searchKey;
        $list->datas     = $data;

        return $list->send();
    }

    /**
     * 余额流水
     *
     * @return mixed
     */
    public function balance()
    {
        $mhm_id = request()->mhm_id;
        $map    = [
            'school_id' => $mhm_id,
            'type'      => 'reduce'
        ];
        if (Request::has('time', 'get', true)) {
            $map['time_slot'] = Request::get('time/a');
        }

        $data = app(SchoolBalanceFlow::class)->getRecordList($map);

        // 定义字段
        $keyList = [
            'create_time' => ListItem::make()->title('时间'),
            'price'       => ListItem::make('custom')->title('变动金额'),
            'balance'     => ListItem::make('custom')->title('变动后金额'),
            'user_name'   => ListItem::make()->title('购买用户'),
            'notes'       => ListItem::make()->title('备注'),
        ];

        // 搜索字段
        $searchKey = [
            'time' => FormItem::make('date')->title(false)->dateType(FormItem::option('DateType', 'DATE_RANGE'))->startPlaceholder('开始时间')->endPlaceholder('结束时间')->format('yyyy-MM-dd')
        ];

        // 设置表单
        $list = app(PageList::class);
        // 表单字段
        $list->pageKey   = $keyList;
        $list->searchKey = $searchKey;
        $list->datas     = $data;

        return $list->send();
    }
}
